package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.mapper.BrandMapper;
import com.ktjiaoyu.pojo.Brand;
import com.ktjiaoyu.service.BrandService;
import com.ktjiaoyu.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Resource
    BrandMapper brandMapper;
    @Resource
    RedisUtil redisUtil;

    @Override
    public List<Brand> selectAll() {
        //先查redis
        List<Brand> list =(List<Brand>)redisUtil.get("AllBrand");
        //如果redis中没有；查询数据库
        if(list==null){
            list=brandMapper.selectAll();
            //保存到redis
            redisUtil.set("AllBrand",list);
        }
        //返回查询到的数据
        return list;
    }
}
